﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="OfficeWebAppsRibbon">
    <File Path="OfficeWebAppsRibbon\Templates\template.dotx" Url="OfficeWebAppsRibbon/Templates/template.dotx" />
    <File Path="OfficeWebAppsRibbon\Templates\template.onepkg" Url="OfficeWebAppsRibbon/Templates/template.onepkg" />
    <File Path="OfficeWebAppsRibbon\Templates\template.pptx" Url="OfficeWebAppsRibbon/Templates/template.pptx" />
    <File Path="OfficeWebAppsRibbon\Images\ExcelWebApp32.png" Url="OfficeWebAppsRibbon/Images/ExcelWebApp32.png" />
    <File Path="OfficeWebAppsRibbon\Images\OneNoteWebApp32.png" Url="OfficeWebAppsRibbon/Images/OneNoteWebApp32.png" />
    <File Path="OfficeWebAppsRibbon\Images\PowerPointWebApp32.png" Url="OfficeWebAppsRibbon/Images/PowerPointWebApp32.png" />
    <File Path="OfficeWebAppsRibbon\Images\WordWebApp32.png" Url="OfficeWebAppsRibbon/Images/WordWebApp32.png" />
    <File Path="OfficeWebAppsRibbon\Images\ExcelWebApp16.png" Url="OfficeWebAppsRibbon/Images/ExcelWebApp16.png" />
    <File Path="OfficeWebAppsRibbon\Images\OneNoteWebApp16.png" Url="OfficeWebAppsRibbon/Images/OneNoteWebApp16.png" />
    <File Path="OfficeWebAppsRibbon\Images\PowerPointWebApp16.png" Url="OfficeWebAppsRibbon/Images/PowerPointWebApp16.png" />
    <File Path="OfficeWebAppsRibbon\Images\WordWebApp16.png" Url="OfficeWebAppsRibbon/Images/WordWebApp16.png" />
  </Module>
  <CustomAction
    Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab"
    Location="CommandUI.Ribbon"
    RegistrationType="List"
    RegistrationId="101">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Tabs._children">
          <Tab Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab" Title="Office Web Apps" Description="Office Web Apps" Sequence="501">
            <Scaling Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.Scaling">
              <MaxSize
                Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.MaxSize"
                GroupId="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup"
                Size="FourLarge"/>
              <Scale
                Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.Scaling.CustomTabScaling"
                GroupId="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup"
                Size="FourLarge" />
            </Scaling>
            <Groups Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.Groups">
              <Group
                Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup"
                Description="Start Office Web Apps"
                Title="Office Web Apps"
                Sequence="52"
                Template="Ribbon.Templates.FourLargeExample">
                <Controls Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.Controls">
                  <Button
                    Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.StartWordWebApp"
                    Command="Gt.OfficeWebAppsLauncher.Command.StartWordWebApp"
                    Sequence="10"
                    Image16by16="/OfficeWebAppsRibbon/Images/WordWebApp16.png"
                    Image32by32="/OfficeWebAppsRibbon/Images/WordWebApp32.png"
                    Description="Create a Word Document using Office Web Applications"
                    LabelText="Create Word Document"
                    TemplateAlias="cust6"/>
                  <Button
                    Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.StartExcelWebApp"
                    Command="Gt.OfficeWebAppsLauncher.Command.StartExcelWebApp"
                    Sequence="20"
                    Image16by16="/OfficeWebAppsRibbon/Images/ExcelWebApp16.png"
                    Image32by32="/OfficeWebAppsRibbon/Images/ExcelWebApp32.png"
                    Description="Create an Excel Document using Office Web Applications"
                    LabelText="Create Excel Document"
                    TemplateAlias="cust7"/>
                  <Button
                    Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.StartPowerPointWebApp"
                    Command="Gt.OfficeWebAppsLauncher.Command.StartPowerPointWebApp"
                    Sequence="30"
                    Image16by16="/OfficeWebAppsRibbon/Images/PowerPointWebApp16.png"
                    Image32by32="/OfficeWebAppsRibbon/Images/PowerPointWebApp32.png"
                    Description="Create a PowerPoint Document using Office Web Applications"
                    LabelText="Create PowerPoint Document"
                    TemplateAlias="cust8"/>
                  <Button
                    Id="Gt.OfficeWebAppsLauncher.Ribbon.CustomTab.OfficeWebAppsGroup.StartOneNoteWebApp"
                    Command="Gt.OfficeWebAppsLauncher.Command.StartOneNoteWebApp"
                    Sequence="40"
                    Image16by16="/OfficeWebAppsRibbon/Images/OneNoteWebApp16.png"
                    Image32by32="/OfficeWebAppsRibbon/Images/OneNoteWebApp32.png"
                    Description="Create a OneNote Document using Office Web Applications"
                    LabelText="Create OneNote Document"
                    TemplateAlias="cust9"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.OneLargeExample">
            <Layout Title="OneLarge" LayoutTitle="OneLarge">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.TwoMediumExample">
            <Layout Title="TwoMedium" LayoutTitle="TwoMedium">
              <Section Alignment="Top" Type="TwoRow">
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust2" />
                </Row>
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust3" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.TwoLargeExample">
            <Layout Title="TwoLarge" LayoutTitle="TwoLarge">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust4" />
                  <ControlRef DisplayMode="Large" TemplateAlias="cust5" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.FourLargeExample">
            <Layout Title="FourLarge" LayoutTitle="FourLarge">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust6" />
                  <ControlRef DisplayMode="Large" TemplateAlias="cust7" />
                  <ControlRef DisplayMode="Large" TemplateAlias="cust8" />
                  <ControlRef DisplayMode="Large" TemplateAlias="cust9" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="Gt.OfficeWebAppsLauncher.Command.StartWordWebApp"
          CommandAction="javascript:StartWordWebApp();"/>
        <CommandUIHandler
          Command="Gt.OfficeWebAppsLauncher.Command.StartExcelWebApp"
          CommandAction="javascript:StartExcelWebApp();"/>
        <CommandUIHandler
          Command="Gt.OfficeWebAppsLauncher.Command.StartPowerPointWebApp"
          CommandAction="javascript:StartPowerPointWebApp();"/>
        <CommandUIHandler
          Command="Gt.OfficeWebAppsLauncher.Command.StartOneNoteWebApp"
          CommandAction="javascript:StartOneNoteWebApp();"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction
    Id="Gt.OfficeWebAppsLauncher.ScriptLinks"
    Location="ScriptLink"
    ScriptBlock="
    function StartOfficeWebAppWithTemplate(template) 
    {
      var context = SP.ClientContext.get_current();
      var web = context.get_web();
      var folder = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList()).get_rootFolder();
      context.load(web);
      context.load(folder);
      context.executeQueryAsync(
        Function.createDelegate(this, function()
        {
          var templateUrl = web.get_serverRelativeUrl();
          if (!templateUrl.endsWith('/')) templateUrl += '/';
          var pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('CreateNewDocument.aspx');
          var builder = new SP.Utilities.UrlBuilder(pageUrl);
          builder.addKeyValueQueryString('id', templateUrl + 'OfficeWebAppsRibbon/Templates/' + template);
          builder.addKeyValueQueryString('SaveLocation', folder.get_serverRelativeUrl());
          builder.addKeyValueQueryString('Source', window.location.href);
          builder.addKeyValueQueryString('DefaultItemOpen', '1');
          var newDocumentUrl = builder.get_url();
          window.location.href = newDocumentUrl;
        }), 
        Function.createDelegate(this, function()
        {
        }));
    }
    function StartWordWebApp() 
    {
      StartOfficeWebAppWithTemplate('template.dotx');
    }
    function StartExcelWebApp() 
    {
      var context = SP.ClientContext.get_current();
      var web = context.get_web();
      var folder = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList()).get_rootFolder();
      context.load(folder);
      context.executeQueryAsync(
        Function.createDelegate(this, function()
        {
          var pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('xlviewer.aspx');
          var builder = new SP.Utilities.UrlBuilder(pageUrl);
          builder.addKeyValueQueryString('new', '1');
          builder.addKeyValueQueryString('SaveLocation', folder.get_serverRelativeUrl());
          builder.addKeyValueQueryString('Source', window.location.href);
          builder.addKeyValueQueryString('DefaultItemOpen', '1');
          var newDocumentUrl = builder.get_url();
          window.location.href = newDocumentUrl;
        }), 
        Function.createDelegate(this, function()
        {
        }));
    }
    function StartPowerPointWebApp() 
    {
      StartOfficeWebAppWithTemplate('template.pptx');
    }
    function StartOneNoteWebApp() 
    {
      StartOfficeWebAppWithTemplate('template.onepkg');
    }
      " />
</Elements>